package com.jijia.webbase.config.response;



import lombok.Getter;
import java.util.HashMap;

@Getter
public class JsonResult extends HashMap<String, Object> {

    // 核心字段常量定义
    private static final String KEY_CODE = "code";
    private static final String KEY_MSG = "msg";
    private static final String KEY_DATA = "data";

    // 无参构造器初始化默认值
    public JsonResult() {
        this.put(KEY_CODE, StatusCode.OPERATION_SUCCESS.getCode());
        this.put(KEY_MSG, StatusCode.OPERATION_SUCCESS.getMsg());
        this.put(KEY_DATA, null);
    }

    // 带StatusCode的构造器
    public JsonResult(StatusCode sc) {
        this.put(KEY_CODE, sc.getCode());
        this.put(KEY_MSG, sc.getMsg());
        this.put(KEY_DATA, null);
    }

    // 带StatusCode和数据的构造器
    public JsonResult(StatusCode sc, Object data) {
        this.put(KEY_CODE, sc.getCode());
        this.put(KEY_MSG, sc.getMsg());
        this.put(KEY_DATA, data);
    }

    // 快捷成功方法
    public static JsonResult ok(Object data) {
        return new JsonResult(StatusCode.SUCCESS, data);
    }

    public static JsonResult ok() {
        return ok(null);
    }

    // 自定义getter方法（兼容原始字段访问）
    public Integer getCode() {
        return (Integer) this.get(KEY_CODE);
    }

    public String getMsg() {
        return (String) this.get(KEY_MSG);
    }

    public Object getData() {
        return this.get(KEY_DATA);
    }
}